<?php

namespace System\AdminBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Base\BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Security\Core\Security;

class MainController extends BaseController
{

    /**
     * 后台登陆页面
     * @Route("/main/login",name="adminLoginPage")
     */
    public function loginAction(Request $request)
    {
        $session = $request->getSession();
//        var_dump($session);die;
        $lastUserName = $session->get(Security::LAST_USERNAME) ? $session->get(Security::LAST_USERNAME) : "";
        if ($session->get(Security::AUTHENTICATION_ERROR)) {
            $message = $session->get(Security::AUTHENTICATION_ERROR)->getMessage() == "Bad credentials." ? "账号或者密码错误" : "";
        } else {
            $message = "";
        }
//        $lastUserName = "";
//        $message = "";
        return $this->render("SystemAdminBundle:Admin:login.html.twig",array(
            "lastUser"  => $lastUserName,
            "message"   => $message
        ));
    }

}
